var app = getApp()
var util = require('../../utils/util.js')
var host = app.globalData.host

// pages/auth.js
Page({

  /**
   * Page initial data
   */
  data: {
    ticketId: '',
  },

  onGotUserInfo(e) {
    console.log(e.detail.errMsg)
    console.log(e.detail.userInfo)
    console.log(e.detail.rawData)
    if (!e.detail.userInfo) {
      console.log('登录失败')
      return;
    }
    // var ticketId = this.data.ticketId
    app.serverLogin({
      success() {
        console.log('login suc')
        wx.navigateBack({
          delta: 1
        })
      },
      fail() {
        console.log('login fail')
      }
    })
    // wx.login({
    //   success(res) {
    //     console.log(res)
    //     if (res.code) {
    //       var url = host + '/xhc/user/auth'
    //       app.request({
    //         url: url,
    //         data: {
    //           code: res.code
    //         },
    //         success: function(res) {}
    //       })
    //     } else {
    //       console.log('登录失败！' + res.errMsg)
    //     }
    //   }
    // })
  },
  /**
   * Lifecycle function--Called when page load
   */
  onLoad: function(options) {
    this.setData({
      ticketId: options.ticketId
    })
  },

  /**
   * Lifecycle function--Called when page is initially rendered
   */
  onReady: function() {

  },

  /**
   * Lifecycle function--Called when page show
   */
  onShow: function() {

  },

  /**
   * Lifecycle function--Called when page hide
   */
  onHide: function() {

  },

  /**
   * Lifecycle function--Called when page unload
   */
  onUnload: function() {

  },

  /**
   * Page event handler function--Called when user drop down
   */
  onPullDownRefresh: function() {

  },

  /**
   * Called when page reach bottom
   */
  onReachBottom: function() {

  },

  /**
   * Called when user click on the top right corner to share
   */
  onShareAppMessage: function() {

  }
})